package com.tk.exam.dao;

import com.tk.exam.domain.TkRPaperQuestion;
import com.tk.exam.domain.TkRPaperQuestionExample;
import com.tk.exam.mapper.TkRPaperQuestionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Auther: fzj
 * @Date: 2019/6/20 0020 15:07
 * @Description:
 */
@Repository
public class TkRPaperQuestionDao {
    @Autowired
    private TkRPaperQuestionMapper tkRPaperQuestionMapper;
    //批量插入
    @Transactional
    public void insertBatch(List<TkRPaperQuestion> tkRPaperQuestions){
        tkRPaperQuestionMapper.insertBatch(tkRPaperQuestions);
    }
    public List<TkRPaperQuestion> findTkRpaperQuesById(Integer examPaperId){
        TkRPaperQuestionExample example = new TkRPaperQuestionExample();
        example.or().andExamPaperIdEqualTo(examPaperId);
        return tkRPaperQuestionMapper.selectByExample(example);
    }
    @Transactional
    public void deleteByIds(List<Integer> ids){
        TkRPaperQuestionExample example = new TkRPaperQuestionExample();
        example.or().andIdIn(ids);
        tkRPaperQuestionMapper.deleteByExample(example);
    }

    public boolean checkQues(List<Integer> ids){
        TkRPaperQuestionExample example = new TkRPaperQuestionExample();
        example.or().andQuestionIdIn(ids);
        List<TkRPaperQuestion> tkRPaperQuestions = tkRPaperQuestionMapper.selectByExample(example);
        if(!CollectionUtils.isEmpty(tkRPaperQuestions)){
            return true;
        }
        return false;
    }
}
